const char WEBPAGE[] PROGMEM = R"=====(
<!DOCTYPE html>
<html lang="en">
  <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>ESP32 Web Server</title>
      <script src="https://code.jquery.com/jquery-3.7.1.slim.min.js" integrity="sha256-kmHvs0B+OpCW5GVHUNjv9rOmY0IvSIRcf7zGUDTDQM8=" crossorigin="anonymous"></script>
  </head>
  <body>
      <h1>Radio stations</h1>
      <p>您可以编辑下面框里的文字来更改、新增或删除电台。每行一个电台，每个电台的格式为两部分[电台名称]，[Url]名称和Url之间用逗号分隔开。</p>

      <button style="visibility: hidden;" onclick="sendCommand('1')">On</button>
      <button style="visibility: hidden;" onclick="sendCommand('0')">Off</button>
      <textarea name="txt1" id="txt1" rows="10" style="width:100%">@Stations</textarea>
      <br>
      <br>
      <div id="readingDisplay"></div>
      <button onclick="getReading('sensor1')">保存</button>

      <script>
        async function sendCommand(command) {
          try {
            const response = await fetch("/toggleLED?action=" + command);
            if (!response.ok)
              throw new Error('Error');
          } catch (error) {
            console.error('Error: ', error);
          }
        }
        
        async function getReading(sensorID) {
          const reading = await fetchReading(sensorID);
          
          document.getElementById('readingDisplay').innerText = reading.value;
        }

        async function fetchReading(sensorID) {
          const dataObject = { "sensorID": sensorID ,"txt1":$("#txt1").val()};

          const json = JSON.stringify(dataObject);

          try {
            const response = await fetch("/updateStations", {
              method: 'POST',
              headers: {
                'Content-Type': 'application/json'
              },
              body: json
            });
            
            if (!response.ok)
              throw new Error('Error');
              
            const data = await response.json();
            
            return data;
          } catch (error) {
            console.error('Error: ', error);
          }
        }
      </script>
  </body>
</html>
)=====";